<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Login extends INSP_Controller {
	
	public function __construct() {
		parent::__construct();
		//$this->load->model("mlogin");		
	}	
	
	function index () {
		$data['base_url'] = base_url();	
		$this->load->view('ctrlpnl/vlogin', $data);
	}
	
	function dologin(){
		$this->load->library('encrypt');
		$baseUrl = base_url();
				
		$username = $this->input->post('username', TRUE, TRUE);
		$password = $this->input->post('password', TRUE, TRUE);
		
		$password1 = $username.$password;
		
		//echo $this->encrypt->encode($password1);
		//exit();
		//
		$sqlstr = "select * from tb_user_account where username= ".$this->db->escape($username)." ";
		//echo $sqlstr;exit;
		$rs		= $this->db->query($sqlstr)->row();
		$num_row = $this->db->query($sqlstr)->num_rows();
				
		if ($num_row == 1){
			if ($password1 == $this->encrypt->decode($rs->password) ){
				$username = $rs->username;
				$fullname = $rs->fullname;
				$data_session = array(
						'username'  => $username,
						'fullname'  => $fullname,
						'accesible' => $rs->accessible,
						'stateid-user' => $rs->stateid,
						'logged_in' => TRUE,
						'tanggal_indonesia' => penanggalan_indonesia()
					);
				$this->session->set_userdata($data_session);
				redirect($baseUrl.'ctrlpnl/beranda');
			}else{
				$this->session->set_flashdata('pesan', 'username atau password salah');
				redirect($baseUrl.'ctrlpnl-insp-jkt-ci3500-admin-area51');
			}
		}else{
			$this->session->set_flashdata('pesan', 'username atau password salah');
			redirect($baseUrl.'ctrlpnl-insp-jkt-ci3500-admin-area51');
		}
	}
	
	function dologout() {
		$baseUrl = base_url();
		$this->session->sess_destroy();
		redirect($baseUrl.'ctrlpnl-insp-jkt-ci3500-admin-area51');
	}
	

}	
